{
  "cells": [
    {
      "metadata": {},
      "cell_type": "markdown",
      "source": "# OpenAltimetry ICESat-2: Elevation Workflow\n\n\n### Overview\n<blockquote>This notebook pulls data from ICESat-2 surface-specific products - ATL06, ATL07, ATL08, ATL10, ATL12, ATL13 via the OpenAltimetry API.</blockquote>\n\n\n\n### Instructions\n<blockquote>Replace the \"OA_API_URL\" string with the data copied from : \"Copy API URL\" from the OpenAltimetry elevation chart and start visualizing your data!</blockquote>\nAuthor: Minh Phan - mnphan@ucsd.edu. Based off the work of Luis Lopez - luis.lopez@nsidc.org"
    },
    {
      "metadata": {
        "trusted": true
      },
      "cell_type": "code",
      "source": "import pandas as pd\nimport json\nimport requests\nimport plotly.graph_objects as go\nfrom plotly.offline import iplot\n\n# We populate a list with the elevation data using the OpenAltimetry API\nOA_API_URL = 'https://openaltimetry.org/data/api/icesat2/atl06?date=2019-09-06&minx=65.77529174029638&miny=64.53861178731293&maxx=66.28615599810888&maxy=65.00003756856293&trackId=1080&beamName=gt3r&beamName=gt3l&beamName=gt2r&beamName=gt2l&beamName=gt1r&beamName=gt1l&outputFormat=json'\n\nOA_API_URL += '&client=jupyter';\n\nOA_BEAMS = ['gt1r', 'gt1l', 'gt2r', 'gt2l', 'gt3r', 'gt3l']\n\ndf_beams = []\noa_plots = []\n\n# This function will request the 6 tracks using OpenAltimetry's API\ndef getData():\n    series = []\n    b_url = OA_API_URL\n\n    print('Requesting data from OA')\n    r = requests.get(b_url)\n    data = r.json()\n    return data\n\n\nelevation_data = getData()\nproduct = elevation_data[\"product\"]\n\nprint('Reading data product: ' + product)\n\nfor series_beam in elevation_data['series']:\n    if any(word in series_beam['beam'] for word in OA_BEAMS):\n        series = []\n        \n        data_name = 'lat_lon_elev'\n        if product == 'ATL08':\n            data_name = 'lat_lon_elev_canopy'\n\n        for p in series_beam[data_name]:\n            series.append({\n                'lat': p[0],\n                'lon': p[1],\n                'h': p[2]\n            })\n            \n        print ('beam ' + series_beam['beam'] + ' - len = ' + str(len(series)))\n\n        if (len(series) > 0):\n            df = pd.DataFrame.from_dict(series)\n            df.name = series_beam['beam']\n            df_beams.append(df)\n            \nprint('df_beams len: ' + str(len(df_beams)))\n\nfor df in df_beams:\n    oa_plots.append(go.Scatter3d(name=df.name, x=df['lat'], y=df['lon'], z=df['h'],\n                                    marker=dict(\n                                        size=2,\n                                        color=df['h'],\n                                        colorscale='Viridis',   # choose a colorscale\n                                        opacity=0.8\n                                    ),\n                                    line=dict(\n                                        color='darkblue',\n                                        width=2\n                                    )\n                                )\n                   )\n\nlayout = go.Layout(\n    width=1200,\n    height=600,\n    scene = dict(aspectmode = 'manual', aspectratio =dict(x=1, y=1, z=0.5),\n                 xaxis=dict(title='Latitude'), yaxis=dict(title='Longitude'), zaxis=dict(title='Elevation (m)'))\n)\n\nprint('Plotting...')\n\nfig = go.Figure(data=oa_plots, layout=layout)\n\niplot(fig)\n",
      "execution_count": null,
      "outputs": []
    },
    {
      "metadata": {
        "trusted": true
      },
      "cell_type": "code",
      "source": "\n",
      "execution_count": null,
      "outputs": []
    }
  ],
  "metadata": {
    "kernelspec": {
      "name": "python36",
      "display_name": "Python 3.6",
      "language": "python"
    },
    "language_info": {
      "mimetype": "text/x-python",
      "nbconvert_exporter": "python",
      "name": "python",
      "pygments_lexer": "ipython3",
      "version": "3.6.6",
      "file_extension": ".py",
      "codemirror_mode": {
        "version": 3,
        "name": "ipython"
      }
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}
